home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Power 1996 September
/
MACPOWER-1996-09.ISO.7z
/
MACPOWER-1996-09.ISO
/
第2特集:プラグイン大集合
/
PIC2 Save
/
ExpMain.c
next >
Wrap
Text File
|
1995-01-14
|
7KB
|
335 lines
/*
File: ExpMain.c (Export Module main procedure)
Copyright © 1995 K&M Software Corporation (番犬 JBE01713@nifty)
Portions © 1992 Adobe Systems Incorporated
Apple Computer, Inc.
© 1994 Metrowerks, Inc.
PIC2 Format © やなぎさわ
1995/01/14 new!
*/
// This file defines some constant procedure which slows your compile.
// Since they are not changed and refered objects only, we divide it.
#ifdef __MWERKS__
#include <A4Stuff.h>
#endif
#include "pic2.h"
#include "PIC2PlugIn.h"
/*****************************************************************************/
/* All calls to the plug-in module come through this routine. It must be
placed first in the resource. To achieve this, most development systems
require that this be the first routine in the source. */
QDGlobals qd;
static asm void asm_copyqd(void)
{
MOVE.L (A5),A0 // Get address of real quickdraw globals
SUB.L #126,A0 // Move to start
LEA qd.randSeed,A1 // Get address of local copy
MOVE.W #64,D0 // Globals are 65 words long
@1: MOVE.W (A0)+,(A1)+ // Copy a word
DBF D0,@1 // Move to next word
rts
}
pascal void ENTRYPOINT(short selector,ExportRecordPtr stuff,long *data,short *result)
{
/* Set up the globals. */
GHdl globals;
#ifdef __MWERKS__
long oldA4 = SetCurrentA4();
asm_copyqd();
#endif
if (!*data)
{
*data = (long) NewHandleClear(sizeof(Globals));
if (!*data)
{
*result = memFullErr;
return;
}
HNoPurge( (Handle) *data);
HLock( (Handle) *data);
InitGlobals((GHdl) *data);
}
globals = (GHdl) *data;
HLock((Handle)globals);
/* Perform the requested operation */
gStuff = stuff;
switch (selector)
{
case exportSelectorAbout:
DoAbout(globals);
break;
case exportSelectorPrepare:
DoPrepare(globals);
break;
case exportSelectorStart:
DoStart(globals);
break;
case exportSelectorContinue:
DoContinue(globals);
break;
case exportSelectorFinish:
DoFinish(globals);
break;
default:
gResult = exportBadParameters;
}
*result = gResult;
HUnlock((Handle)globals);
#if defined(__MWERKS__)
SetA4(oldA4); // Does not support PC-relative string index
#else
RestoreA4 ();
#endif
}
/*****************************************************************************/
/* UserItem to outline the OK button in a dialog box. */
pascal void static_OutlineOK(DialogPtr dp, short item)
{
PenState originalPenState;
Rect r;
Handle h;
short itemType;
GetPenState (&originalPenState);
item = ok;
GetDItem (dp, item, &itemType, &h, &r);
PenNormal ();
PenSize (3, 3);
InsetRect (&r, -4, -4);
FrameRoundRect (&r, 16, 16);
SetPenState (&originalPenState);
}
/*****************************************************************************/
void SetOutlineOKHook(DialogPtr dp, short hookItem)
{
short itemType;
Rect r;
Handle h;
GetDItem (dp, hookItem, &itemType, &h , &r);
SetDItem (dp, hookItem, itemType, (Handle) &static_OutlineOK, &r);
}
/*****************************************************************************/
/* Calls the host's TestAbort function */
pascal Boolean DoTestAbort (ProcPtr codeAddress) = {0x205F, 0x4E90};
/* Calls the host's TestAbort function */
Boolean TestAbort (GHdl globals)
{
return DoTestAbort(gStuff->abortProc);
}
/*****************************************************************************/
pascal void DoUpdateProgress (long done, long total, ProcPtr codeAddress) = {0x205F, 0x4E90};
/* Calls the host's UpdateProgress procedure */
void UpdateProgress(GHdl globals,long done, long total)
{
DoUpdateProgress (done, total, gStuff->progressProc);
}
/*****************************************************************************/
/* Centers a dialog template 1/3 of the way down on the main screen. */
/* The following routine locates the QuickDraw globals. */
// See TN M.PT.StandAloneCode, Technical Notes #110
typedef struct QDVars
{
char privates[76];
long randSeed;
BitMap screenBits;
Cursor arrow;
Pattern dkGray;
Pattern ltGray;
Pattern gray;
Pattern black;
Pattern white;
GrafPtr thePort;
} QDVars;
static QDVars *GetQDVars(void)
{
return (QDVars *) ((* (char **) SetCurrentA5 ()) -
(sizeof (QDVars) - sizeof (GrafPtr)));
}
/*****************************************************************************/
/* Set the cursor to the arrow cursor. */
void SetArrowCursor(void)
{
QDVars *qd = GetQDVars();
SetCursor (&(qd->arrow));
}
/*****************************************************************************/
#define menuHeight 20
void CenterDialog (DialogTHndl dt)
{
Rect r;
short width;
short height;
QDVars *qd = GetQDVars ();
width = qd->screenBits.bounds.right;
height = qd->screenBits.bounds.bottom;
r = (**dt).boundsRect;
OffsetRect (&r, -r.left, -r.top);
OffsetRect (&r, (width - r.right) / 2,
(height - r.bottom - menuHeight) / 3 + menuHeight);
(**dt).boundsRect = r;
}
#undef menuHeight
/*****************************************************************************/
void ReplyToSpec(FSSpec *spec, SFReply *reply)
{
short aVolNum;
long aDirID, aProcID;
GetWDInfo(reply->vRefNum, &aVolNum, &aDirID, &aProcID);
BlockMove(reply->fName, spec->name, reply->fName[0]+1);
spec->vRefNum = aVolNum;
spec->parID = aDirID;
}
/*****************************************************************************/
/* Displays the about dialog box for the plug-in module. */
void DoAbout(GHdl globals)
{
short item;
DialogPtr dp;
DialogTHndl dt;
gResult = noErr;
dt = (DialogTHndl) GetResource ('DLOG', kAboutDialogID);
HNoPurge ((Handle) dt);
CenterDialog (dt);
dp = GetNewDialog (kAboutDialogID, nil, (WindowPtr) -1);
ParamText((StringPtr)cPIC2SaveVersion,(StringPtr)NULL,(StringPtr)NULL,(StringPtr)NULL);
ModalDialog (nil, &item);
DisposDialog (dp);
HPurge ((Handle) dt);
}
/*****************************************************************************/
/* Displays the error dialog box for the plug-in module. */
#define OKhookItem 3
void DoError(GHdl globals,StringPtr p1,StringPtr p2)
{
short item;
DialogPtr dp;
DialogTHndl dt;
Str15 st3;
dt = (DialogTHndl) GetResource ('DLOG', kErrorDialogID);
HNoPurge ((Handle) dt);
CenterDialog (dt);
dp = GetNewDialog (kErrorDialogID, nil, (WindowPtr) -1);
if(p2==NULL) p2=(StringPtr)st3;
st3[0]=0;
ParamText(p1,p2,NULL,NULL);
SetOutlineOKHook(dp,OKhookItem);
ModalDialog (nil, &item);
DisposDialog (dp);
HPurge ((Handle) dt);
}
#undef OKhookItem
// Color conversion
unsigned short nbitsto8(unsigned short xbits, short n)
{
unsigned short p,q;
short i;
if(n==0 || n>=8) return xbits;
#if 1
p=0;
q=xbits << (8-n);
for(i=8/n;i>=0;i--)
{
p >>= n;
p |= q;
}
return p;
#else
return xbits;
#endif
}